import { ref, onMounted, onUnmounted } from 'vue';
import moment from "moment"

export default function useNowDate() {
    const nowDateTime = ref()
    const nowDateTimeArray = ref<string[]>([])

    function _getNowDate() {
        nowDateTime.value = moment().format("YYYY-MM-DD HH:mm:ss")
    }

    function _getNowDateArray() {
        nowDateTimeArray.value = moment().format("YYYY-MM-DD-HH-mm-ss").split('-')
    }

    let dateInterval:any = 0;

    onMounted(() => {
        dateInterval = setInterval(() => {
            _getNowDate()
            _getNowDateArray()
        }, 1000)
    })

    onUnmounted(() => clearInterval(dateInterval))

    return {
        nowDateTime,
        nowDateTimeArray
    }
}